import java.util.HashSet;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2024-03-06
 * Time:20:56
 */
public class Solution {
    public boolean checkSubarraySum(int[] nums, int k) {
        HashSet<Integer> set = new HashSet<>();
        int[] sum = new int[nums.length+1];
        for(int i = 1;i <= nums.length;i++) {
            sum[i] = sum[i-1] + nums[i-1];

        }
        for(int i = 2;i < sum.length;i++) {
            int res = sum[i] % k;
            set.add(sum[i-2] % k);
            if(set.contains(res)) return true;
        }
        return false;
    }

}
